//
//  CDSetOneDetailController.m
//  CuriosityDaily3
//
//  Created by donghao on 16/9/26.
//  Copyright © 2016年 theBestTeam. All rights reserved.
//

#import "CDSetOneDetailController.h"

@interface CDSetOneDetailController ()

@property(nonatomic,weak) UITextField *textField;

@end

@implementation CDSetOneDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor darkGrayColor];
    
    [self setupUI];
    

}
- (void)setNbar {
    self.navigationController.navigationBar.titleTextAttributes = @{ NSForegroundColorAttributeName: [UIColor whiteColor] };
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    
}

/**
 *  设置界面
 */
- (void)setupUI {
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    
    [self.view addSubview:scrollView];
    scrollView.backgroundColor = [UIColor clearColor];
    CGRect frame = CGRectMake(0, 20, self.view.frame.size.width, 44);
    UITextField *textField = [[UITextField alloc] initWithFrame:frame];
    textField.textColor = [UIColor whiteColor];
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.backgroundColor = [UIColor colorWithRed:0.989 green:1.000 blue:1.000 alpha:0.283];
    [scrollView addSubview:textField];
    [textField becomeFirstResponder];
    textField.text = self.desc;
    self.textField = textField;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"保存" forState:UIControlStateNormal];
//    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    button.bounds = CGRectMake(0, 0, 45, 20);
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = saveButton;
    
    [button addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void)save {
    
    if ([self.textField hasText]) {
        self.desc = self.textField.text;
        if (self.detailBlock) {
            [SVProgressHUD showSuccessWithStatus:@"修改成功"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [SVProgressHUD dismiss];
                self.detailBlock(self.desc);
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
    } else {
//        [SVProgressHUD showWithStatus:@"修改的信息不能为空"];
        [SVProgressHUD showErrorWithStatus:@"修改的信息不能为空"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
    }
    
}



@end
